cd "/Users/Glenn/Dropbox (ASU)/reclaim/replication_files/"

************
**	Programs to replicate figures in 
**	"On the measurement of environmental inequality: 
**	Ranking emissions distributions generated by different policy instruments"
**	by Erin Mansur and Glenn Sheriff
************
//	imported ado files:
	*ssc install glcurve
	*ssc install lorenz

// 	general graph settings:
	graph set window fontface "Times New Roman"
	*ssc install blindschemes
	set scheme plotplainblind
	
************
**	Figures 3, 4, 6, 7, 8
************

// this program generates all the curves used in main text figures

capture program drop curves
program curves

	foreach n in 1 3  {	
		foreach k in 1990 2000 {
			use ej , clear 
			// note: variable ejX denotes population in CBG for group X (see variable labels)
			keep if year == `k' & dispersion == `n'
			foreach j in nox1 nox2 control2 {
				capture drop s`j'
				gen s`j' = -`j' // convert exposure to negative value to rank from high to low
				forval i = 1/8 {
					glcurve `j' [fweight = ej`i'] 	, lorenz pvar(L`j'x`i'_`k') ///
						glvar(L`j'y`i'_`k') sortvar(s`j') nograph   replace 
					glcurve `j' [fweight = ej`i'] 	,  pvar(GL`j'x`i'_`k') ///
						glvar(GL`j'y`i'_`k') sortvar(s`j') nograph   replace
					lorenz `j' [fweight = ej`i'] 	, absolute pvar(s`j') 
					matrix temp = e(b) 
					matrix AL`j'y`i'_`k' = temp'
					svmat AL`j'y`i'_`k' 
					ren AL`j'y`i'_`k'1 AL`j'y`i'_`k'
				}
			}
			
			matrix temp = e(p)
			matrix p = temp'
			svmat p
			ren p1 p
			replace p = p/100
			
			keep L* GL* AL* p
		
			save GL_`n'_`k', replace
		}
		
		append using GL_`n'_1990
	
		foreach g in AL L GL {	
			foreach j in nox1 nox2 control2 {
				foreach k in 1990 2000 {
					la var `g'`j'y1_`k' "Total"
					la var `g'`j'y2_`k' "Hispanic"
					la var `g'`j'y3_`k' "White"
					la var `g'`j'y4_`k' "Black"
					la var `g'`j'y5_`k' "Other"
					la var `g'`j'y6_`k' "Below Poverty"
					la var `g'`j'y7_`k' "1-2 × Poverty"
					la var `g'`j'y8_`k' "Above 2 × Poverty"
				}
			}
		}
	
		save curves_`n', replace

		foreach g in AL GL {
			forval i = 1/8 {
				if "`g'" == "GL" {		
					loc yl 0(25)75
					loc ii : var label `g'nox2y`i'_1990
					
					//RECLAIM 1990 census v RECLAIM 2000 census
					scatter (`g'nox2y`i'_1990 `g'nox2x`i'_1990) , sort ///
					msymbol (i i ) connect(L L ) lcolor(black ) ///
					ylabel(`yl' `yu',  labsize(huge) ) xlabel(, labsize(huge)) ///
					title("`ii'", size(vhuge) pos(12)) ///
					ytitle("") xtitle("") lwidth(vthick ..) ///
					legend(off) ///
					|| scatter (`g'nox2y`i'_2000 `g'nox2x`i'_2000) , ///
						sort msymbol (i ) connect( L ) lcolor(gray )  lwidth(vthick ..)
				
					graph export "compare_`g'_census_ej`i'_`n'.eps", replace fontface(Times)
					// generate legend	
					line  (GLnox2y2_1990 GLnox2x2_1990 GLnox2y2_1990) if GLnox2y2_1990 == 0 ,  ///
						legend(label(1 "1990" ) label(2 "2000") ring(0) pos(0) rows(1)) ///
						yscale(off) xscale(off) plotregion(lcolor(white)) lwidth(thick ..) ///
						ytitle("") xtitle("")  lcolor(black gray) lpattern(solid ..)
					graph export "legend_census.eps", replace fontface(Times)
				
					if `n' == 1 loc yl 0(100)500
					if `n' == 3 loc yl 0(50)250
					loc ii : var label `g'nox2y`i'_1990
				
					//Period 1 v RECLAIM 1990 census v CAC 1990 census	
					scatter (`g'nox1y`i'_1990 `g'nox1x`i'_1990) , sort ///
						msymbol (i i ) connect(L L )  lwidth(vthick ..)  ///
						ylabel(`yl'  , labsize(huge) ) xlabel(, labsize(huge)) ///
						title("`ii'", size(vhuge) pos(12)) ///
						ytitle("") xtitle("")  lcolor(black ) lpattern(solid ) ///
						legend(off) ///
						|| scatter (`g'nox2y`i'_1990 `g'nox2x`i'_1990) ,  ///
							sort msymbol (i ) connect( L )  lwidth(vthick ..)  lcolor( gray )  ///
						|| scatter (`g'control2y`i'_1990 `g'control2x`i'_1990) ,  ///
							sort msymbol (i ) connect( L )   lwidth(vthick ..)  lcolor(black) lpattern( dash )
				}	
				else {
					loc ii : var label `g'nox2y`i'_1990
					scatter (`g'nox1y`i'_1990 p) , sort ///
						msymbol (i i ) connect(L L )  lwidth(vthick ..)  ///
						ylabel(0(50)150  ,  labsize(huge) ) xlabel(, labsize(huge)) ///
						title("`ii'", size(vhuge) pos(12))  lcolor(black ) lpattern(solid ) ///
						ytitle("") xtitle("")  ///
						legend(off) ///
						|| scatter (`g'nox2y`i'_1990 p) ,  ///
							sort msymbol (i ) connect( L )  lwidth(vthick ..)  lcolor(gray)  ///
						|| scatter (`g'control2y`i'_1990 p) ,  ///
							sort msymbol (i ) connect( L ) lwidth(vthick ..)  lcolor( black) lpattern( dash )
				}
		
				graph export "compare_`g'_policy_ej`i'_`n'.eps", replace fontface(Times)
				line  (GLnox2y2_1990 GLnox2x2_1990 GLnox2y2_1990 GLnox2y2_1990)  if GLnox2y2_1990 == 0 , ///
					legend(label(1 "Period 1" ) label(2 "RECLAIM") label(3 "Command and control") ring(0) pos(0) rows(1)) ///
					yscale(off) xscale(off) plotregion(lcolor(white)) lwidth(thick ..) ///
					ytitle("") xtitle("")  lcolor(black gray black) lpattern(solid solid dash )
				graph export "legend_policy.eps", replace fontface(Times)
		
			}
		}
	
		// compare relative demographic group welfare under each policy with main dispersion model
		
		if `n' == 3 {
			foreach k in nox1 nox2 control2 {
				if  "`k'" == "nox1" {
					loc kk "Period 1"
					loc yl 0(50)275
				}
				if 	"`k'" == "nox2" {
					loc kk "RECLAIM"
					loc yl 0(25)75
				}
				if  "`k'" == "control2" {
					loc kk "Command and control"
					loc yl 0(25)100
				}
				loc g GL
		
				
				scatter (`g'`k'y4_1990 `g'`k'x4_1990) ,  sort ///
						msymbol (i i ) connect(L L )  lwidth(vthick ..) ///
						ylabel(`yl', labsize(huge) ) xlabel(, labsize(huge)) ///
						title("`kk'", size(vhuge) pos(12))  lcolor(black )  ///
						ytitle(""  , size(vlarge)) ///
						xtitle(""  , size(vlarge))  ///
						legend(off) ///
						|| scatter (`g'`k'y2_1990 `g'`k'x2_1990) , sort msymbol (i ) connect( L )  lwidth(vthick ..)  lcolor(gray)  ///
						|| scatter (`g'`k'y3_1990 `g'`k'x3_1990) , sort msymbol (i ) connect( L )  lwidth(vthick) lcolor(black) lpattern( dash )  ///
						|| scatter (`g'`k'y5_1990 `g'`k'x5_1990) , sort msymbol (i ) connect( L )  lwidth(medium) lcolor( black) lpattern(solid)
			
				graph export "compare_`g'_race_`k'_`n'.eps", replace fontface(Times)
				line  (GLnox2y2_1990 GLnox2x2_1990 GLnox2y2_1990 GLnox2y2_1990 GLnox2y2_1990)  if GLnox2y2_1990 == 0 , ///
						legend(label(1 "Black" ) label(2 "Hispanic") label(3 "White") label(4 "Other") ///
						ring(0) pos(0) rows(1)) lwidth(thick thick thick medium) ///
						yscale(off) xscale(off) plotregion(lcolor(white)) ///
						ytitle("") xtitle("")  lcolor(black gray black black) lpattern(solid solid dash solid )
				graph export "legend_race.eps", replace fontface(Times)
			
				scatter (`g'`k'y6_1990 `g'`k'x6_1990) , sort ///
						msymbol (i i ) connect(L L ) lwidth(vthick ..) ///
						ylabel(`yl', labsize(huge) ) xlabel(, labsize(huge)) ///
						title("`kk'", size(vhuge) pos(12))  ///
						ytitle("" , size(vlarge)) ///
						xtitle("" , size(vlarge))  ///
						legend(off)  ///
						|| scatter (`g'`k'y7_1990 `g'`k'x7_1990) , sort msymbol (i ) connect( L )  lwidth(vthick ..)  lcolor(gray)  ///
						|| scatter (`g'`k'y8_1990 `g'`k'x8_1990) , sort msymbol (i ) connect( L )  lwidth(vthick ..)  lcolor( black) lpattern( dash)
				
				graph export "compare_`g'_income_`k'_`n'.eps", replace fontface(Times)
				line  (GLnox2y2_1990 GLnox2x2_1990 GLnox2y2_1990 GLnox2y2_1990 )  if GLnox2y2_1990 == 0 , ///
						 lwidth(thick ..) ///
						legend(label(1 "Below Poverty" ) label(2 "1 - 2 × Poverty") label(3 "Above 2 × Poverty")  ///
						ring(0) pos(0) rows(1)) ///
						yscale(off) xscale(off) plotregion(lcolor(white)) ///
						ytitle("") xtitle("")   lcolor(black gray black) lpattern(solid solid dash )
				graph export "legend_income.eps", replace fontface(Times)		
				
			}
		}
	}
end

// this program generates all the curves used in appendix text figures
capture program drop curves_app
program curves_app

	foreach n in 3 9 {
		// no hysplit data for 2000 cbg
		*use ej`n'`k'_gs_reclaim, clear
		loc k 1990
		use ej_reclaim, clear
		keep if year == 1990 & dispersion == `n'
		foreach j in nox1 nox2 control2 {
			capture drop s`j'
			gen s`j' = -`j'
			forval i = 1/8 {
				glcurve `j' [fweight = ej`i'] , lorenz pvar(L`j'x`i'_`k') ///
					glvar(L`j'y`i'_`k') sortvar(s`j') nograph   replace 
				glcurve `j' [fweight = ej`i']  ,  pvar(GL`j'x`i'_`k') ///
					glvar(GL`j'y`i'_`k') sortvar(s`j') nograph   replace
				qui lorenz `j' [fweight = ej`i']  , absolute pvar(s`j') 
				matrix temp = e(b) 
				matrix AL`j'y`i'_`k' = temp'
				svmat AL`j'y`i'_`k' 
				ren AL`j'y`i'_`k'1 AL`j'y`i'_`k'
			}
		}
		
		matrix temp = e(p)
		matrix p = temp'
		svmat p
		ren p1 p
		replace p = p/100
		
		keep L* GL* AL* p
		

		save GL_`n'_`k', replace
	
		
		append using GL_`n'_1990
			
		loc g GL
		loc k 1990
		foreach j in nox1 nox2 control2 {
			la var `g'`j'y1_`k' "Total"
			la var `g'`j'y2_`k' "Hispanic"
			la var `g'`j'y3_`k' "White"
			la var `g'`j'y4_`k' "Black"
			la var `g'`j'y5_`k' "Other"
			la var `g'`j'y6_`k' "Below Poverty"
			la var `g'`j'y7_`k' "1-2 × Poverty"
			la var `g'`j'y8_`k' "Above 2 × Poverty"
		}
	
	
		save curves_`n', replace
		//RECLAIM 1990 census v RECLAIM 2000 census
		
		forval i = 1/8 {
		//Period 1 v RECLAIM 1990 census v CAC 1990 census
			if `n' == 3 loc yl 0(25)75
			if `n' == 9 loc yl 0(.5)2 
			loc ii : var label `g'nox2y`i'_1990
			scatter (`g'nox1y`i'_1990 `g'nox1x`i'_1990) , sort ///
				msymbol (i i ) connect(L L )  lwidth(vthick ..)  ///
				ylabel(`yl'  , labsize(huge) ) xlabel(, labsize(huge)) ///
				title("`ii'", size(vhuge) pos(12)) ///
				ytitle("") xtitle("")  lcolor(black ) lpattern(solid ) ///
				legend(off) ///
				|| scatter (`g'nox2y`i'_1990 `g'nox2x`i'_1990) ,  ///
					sort msymbol (i ) connect( L )  lwidth(vthick ..)  lcolor( gray )  ///
				|| scatter (`g'control2y`i'_1990 `g'control2x`i'_1990) ,  ///
					sort msymbol (i ) connect( L )   lwidth(vthick ..)  lcolor(black) lpattern( dash )
		
		
			graph export "compare_`g'_policy_ej`i'_`n'_reclaim.eps", replace fontface(Times)
			line  (GLnox2y2_1990 GLnox2x2_1990 GLnox2y2_1990 GLnox2y2_1990)  if GLnox2y2_1990 == 0 , ///
				legend(label(1 "Period 1" ) label(2 "RECLAIM") label(3 "Command and control") ring(0) pos(0) rows(1)) ///
				yscale(off) xscale(off) plotregion(lcolor(white)) lwidth(thick ..) ///
				ytitle("") xtitle("")  lcolor(black gray black) lpattern(solid solid dash )
			graph export "legend_policy_reclaim.eps", replace fontface(Times)
		
		}

	}
		
end


// Figure 5
capture program drop maps
program maps
	shp2dta using bg06_d90, data("bg_06d90")  coor("bg_06d90_cords") replace 

	foreach n in 1 3  {

		use ej, clear

		//only keep sc
		keep if SCAQMD == 1 & year == 1990 & dispersion == `n'
		
		gen pct_white = ej3/ej1
		gen pct_poor = 1-ej8/ej1
		egen max_exp = max(nox1)
		gen pct_exp = nox1/max_exp
		egen max_pop = max(ej1)
		gen pct_pop = ej1/max_pop 
		
		gen minority = ej1-ej3
		gen poor = 1-ej8
		
		replace pct_white = round(pct_white,.01)
		gen pct_minority = 1-pct_white


		save temp, replace

		use bg_06d90, clear
		gen double id = real(GEOID)
		//make ids conform w main data by dropping CA prefix
		replace id = id -060000000000
		//get rid of duplicate bg by keeping only largest
		bysort id: egen double temp = max(AREA)
		keep if AREA == temp
		//merge block group map info w data
		merge 1:1 id using temp
		//south coast flag
		gen flag_sc = ( _merge == 3)
		drop _merge

		
		gen pop_den = ej1/AREA
		egen pop_max = max(pop_den)
		replace pct_pop = pop_den/pop_max
		drop if ej1 == .  // gets rid of cbg outside scaqmd
		xtile ptile_pop = pct_pop,nq(100)
		xtile ptile_minority = pct_minority,nq(100)
		xtile ptile_poor = pct_poor,nq(100)
		xtile ptile_exp = pct_exp,nq(100)
		 

		save temp`n', replace
		
		use bg_06d90_cords , clear
		//merge polygons w data
		merge m:1 _ID using temp`n'
		drop _merge
		save bg_map`n', replace

		//get top 25 emitters
		use facilities, clear

		gsort - nox1
		keep in 1/25
		keep ufacid nox1 lat lon
		save temp2, replace

		use bg_map`n' , clear
		sort _ID
		keep if flag_sc == 1
		save temp_map`n' , replace
		
		//generate map of sc outline
		use temp`n' , clear
		mergepoly if flag_sc == 1 using temp_map`n' , coordinates(sc_outline) replace
					

		if `n' == 3 {
			use temp`n' , clear			
		
			
			spmap ptile_minority  if flag_sc == 1 & ptile_pop>10 using temp_map`n', id(_ID) fcolor(OrRd) osize(none none none none none) ///
				point(x(lon) y(lat) data(temp2) size(small) fcolor(black) ocolor(black)) ///
				clmethod(custom) clbreaks(0 25 50 75 90 100)  ndsize(none) ///
				polygon(data(sc_outline)) plotregion(margin(0 0 -40 0)) ///
				 legenda(on) legtitle("Percentile")
			graph export "map_minority_crop.eps", replace fontface(Times)	
				
			spmap ptile_poor if flag_sc == 1 & ptile_pop>10 using temp_map`n', id(_ID) fcolor(OrRd) osize(none none none none none) ///
				point(x(lon) y(lat) data(temp2) size(small) fcolor(black) ocolor(black)) ///
				clmethod(custom) clbreaks(0 25 50 75 90 100)  ndsize(none) ///
				polygon(data(sc_outline)) plotregion(margin(0 0 -40 0)) ///
				legenda(on) legtitle("Percentile")
			
			graph export "map_poor_crop.eps", replace fontface(Times)		
		}

		use temp`n' , clear
		if `n' == 3 loc x 3 km radius
		if `n' == 9 loc x HYSPLIT

		spmap ptile_exp if flag_sc == 1 & ptile_pop>10 using temp_map`n', id(_ID) fcolor(OrRd) osize(none none none none none) ///
			point(x(lon) y(lat) data(temp2) size(small) fcolor(black) ocolor(black)) ///
			clmethod(custom) clbreaks(0 25 50 75 90 100)  ndsize(none) ///
			polygon(data(sc_outline)) plotregion(margin(0 0 -40 0)) ///
			 legenda(on) legtitle("Percentile")

		graph export "map_exp_`n'_pop.eps", replace fontface(Times)
	}
	erase temp.dta
	erase temp2.dta
	foreach n in 1 3 {
		erase temp`n'.dta
		erase bg_map`n'.dta
		erase temp_map`n'.dta
	}
end


// Figure A1

capture program drop figure_a1 //illustrative histograms
program figure_a1

		use ej, clear 
		keep if year == 1990 & dispersion == 3
		
		drop if nox1 == 0 // only keep census block groups affected by RECLAIM facilities
		foreach i in nox1 nox2 control2 {
			if "`i'" == "nox1" loc ii Period 1
			if "`i'" == "nox2" loc ii RECLAIM
			if "`i'" == "control2" loc ii Command and control
			
			graph twoway kdensity `i' ,  ///
				yscale(r(.025)) ylabel(0(.005).025 , labsize(vlarge)) xlabel(0(1000)7500 , labsize(vlarge)) ///		
				xtitle("")	ytitle("" ) title("`ii'", size(vhuge)) xscale(r(7500))
			graph save kdens_`i'_1990, replace
			graph export "kdens_`i'_1990.eps", replace fontface(Times)					
		}
	
end

// Figure A2

capture program drop figure_a2
program figure_a2

	
	use ej, clear
	keep if year == 1990 & dispersion == 3

	glo p 1 "0-50" 2 "50-100" 3 "100-150" 4 "150-200" 5 "200-250" 6 "250-300" 7 "300-350" 8 "350-400" 9 ">400"

	gen cat = 1 if nox2 <=50
	replace cat = 2 if nox2 >50 & nox2 <=100
	replace cat = 3 if nox2 >100 & nox2 <=150
	replace cat = 4 if nox2 >150 & nox2 <=200
	replace cat = 5 if nox2 >200 & nox2 <=250
	replace cat = 6 if nox2 >250 & nox2 <=300
	replace cat = 7 if nox2 >300 & nox2 <=350
	replace cat = 8 if nox2 >350 & nox2 <=400
	replace cat = 9 if nox2 >400 
	
	collapse (sum) ej* , by(cat)
	renvars ej* , postfix(_1990)
	save temp , replace
	use ej, clear
	keep if year == 2000 & dispersion == 3
	
	gen cat = 1 if nox2<=50
	replace cat = 2 if nox2>50 & nox2<=100
	replace cat = 3 if nox2>100 & nox2<=150
	replace cat = 4 if nox2>150 & nox2<=200
	replace cat = 5 if nox2>200 & nox2<=250
	replace cat = 6 if nox2>250 & nox2<=300
	replace cat = 7 if nox2>300 & nox2<=350
	replace cat = 8 if nox2>350 & nox2<=400
	replace cat = 9 if nox2>400 
	
	collapse (sum) ej* , by(cat)
	renvars ej* , postfix(_2000)
	merge 1:1 cat using temp

	forval i = 1/9 {
		gen diff_`i' = ej`i'_2000 - ej`i'_1990
		replace diff_`i' = diff_`i'/1000
	}
	label define p_label $p
	label values cat p_label 
	la var diff_1 "Total"
	la var diff_2 "Hispanic"
	la var diff_3 "White"
	la var diff_4 "Black"
	la var diff_5 "Other"
	la var diff_6 "Below poverty"
	la var diff_7 "1-2×poverty"
	la var diff_8 "Above 2×poverty"
	la var diff_9 "Income unknown"

	scatter diff_4 diff_2 diff_3 diff_5 cat , sort xlabel(1(1)9,valuelabel) legend(rows(1) pos(6) ) ///
		xtitle("") 
		graph export "race_sort.eps", replace fontface(Times)
	scatter diff_6 diff_7 diff_8  cat , sort xlabel(1(1)9,valuelabel) legend(rows(1) pos(6) ) ///
		xtitle("") 
		graph export "income_sort.eps", replace fontface(Times)
	erase temp.dta

end




capture program drop maps_reclaim
program maps_reclaim

	foreach n in  3 9 {
	
	//create maps of race, income, exposure (circle and grainger), and density

	use ej_reclaim, clear
	keep if dispersion == `n' & year == 1990 
	
	//only keep sc
	
	gen pct_white = ej3/ej1
	gen pct_poor = 1-ej8/ej1
	egen max_exp = max(nox1)
	gen pct_exp = nox1/max_exp
	egen max_pop = max(ej1)
	gen pct_pop = ej1/max_pop 
	
	gen minority = ej1-ej3
	gen poor = 1-ej8
	
	replace pct_white = round(pct_white,.01)
	gen pct_minority = 1-pct_white


	save temp, replace

	use bg_06d90, clear
	gen double id = real(GEOID)
	//make ids conform w main data by dropping CA prefix
	replace id = id -060000000000
	//get rid of duplicate bg by keeping only largest
	bysort id: egen double temp = max(AREA)
	keep if AREA == temp
	//merge block group map info w data
	merge 1:1 id using temp
	//south coast flag
	gen flag_sc = ( _merge == 3)
	drop _merge

	
	gen pop_den = ej1/AREA
	egen pop_max = max(pop_den)
	replace pct_pop = pop_den/pop_max
	drop if ej1 == .  // gets rid of cbg outside scaqmd
	xtile ptile_pop = pct_pop,nq(100)
	xtile ptile_minority = pct_minority,nq(100)
	xtile ptile_poor = pct_poor,nq(100)
	xtile ptile_exp = pct_exp,nq(100)
	 

	save temp`n', replace
	
	use bg_06d90_cords , clear
	//merge polygons w data
	merge m:1 _ID using temp`n'
	drop _merge
	save bg_map`n', replace

	//get top 25 emitters
	use facilities, clear
		
	
	gsort - nox1
	keep in 1/25
	keep ufacid nox1 lat lon
	save temp2, replace

	*use scaqmd, clear


	*spmap  using scaqmd_cords, id(OBJECTID)  point(x(lon) y(lat) data(temp2) size(tiny)) ///
	*			polygon(data(bg_map) osize(none none)  ///
	*			select(keep if flag_sc == 1 & flag_wh == 1) by(flagw) fcolor(Blues))

	use bg_map`n' , clear
	sort _ID
	keep if flag_sc == 1
	save temp_map`n' , replace
	
	//generate map of sc outline
	use temp`n' , clear
	mergepoly if flag_sc == 1 using temp_map`n' , coordinates(sc_outline) replace
				

	if `n' == 3 {
		use temp`n' , clear			
	
		
				 spmap ptile_minority if flag_sc == 1 & ptile_pop>10 using temp_map`n', id(_ID) fcolor(OrRd) osize(none none none none none) ///
			point(x(lon) y(lat) data(temp2) size(small) fcolor(black) ocolor(black)) ///
					clmethod(custom) clbreaks(0 25 50 75 90 100)  ndsize(none) ///
					polygon(data(sc_outline)) plotregion(margin(0 0 -40 0)) ///
					 legenda(on) legtitle("Percentile")
	
		graph export "map_minority_crop_reclaim.eps", replace fontface(Times)	
		
			
			

			
		 spmap ptile_poor if flag_sc == 1 & ptile_pop>10 using temp_map`n', id(_ID) fcolor(OrRd) osize(none none none none none) ///
			point(x(lon) y(lat) data(temp2) size(small) fcolor(black) ocolor(black)) ///
					clmethod(custom) clbreaks(0 25 50 75 90 100)  ndsize(none) ///
					polygon(data(sc_outline)) plotregion(margin(0 0 -40 0)) ///
					 legenda(on) legtitle("Percentile")
		
		graph export "map_poor_crop_reclaim.eps", replace fontface(Times)
		
		
	}
	

		use temp`n' , clear
		if `n' == 3 loc x 3 km radius
		if `n' == 9 loc x HYSPLIT


		spmap ptile_exp if flag_sc == 1 & ptile_pop>10 using temp_map`n', id(_ID) fcolor(OrRd) osize(none none none none none) ///
			point(x(lon) y(lat) data(temp2) size(small) fcolor(black) ocolor(black)) ///
					clmethod(custom) clbreaks(0 25 50 75 90 100)  ndsize(none) ///
					polygon(data(sc_outline)) plotregion(margin(0 0 -40 0)) ///
					 legenda(on) legtitle("Percentile")
	
		graph export "map_exp_`n'_pop_reclaim.eps", replace fontface(Times)
	}
	erase temp.dta
	erase temp2.dta
	foreach n in 3 9 {
		erase temp`n'.dta
		erase bg_map`n'.dta
		erase temp_map`n'.dta
	}
	
end


	
	
	
	

	

	
